package 数据结构与算法.实验二;

public class Stack_2 {
    private int[] stack;
    private int SIZE;
    private int length;

    Stack_2(){
        this.SIZE = 5;
        this.length = 0;
        this.stack = new int[this.SIZE];
    }

    public void push(int elem) throws Exception{

        if(length >= SIZE){
            throw new Exception("Stackoverflow");
        }
        stack[length++] = elem;
    }

    public int pop() throws Exception{
        if(length <= 0){
            throw new Exception("Stack");
        }
        return stack[--length];
    }

}
